package com.z6school.manage.controller;

import com.z6school.manage.common.pojo.CurrScore;
import com.z6school.manage.common.pojo.JsonResult;
import com.z6school.manage.common.pojo.ScoreVo;
import com.z6school.manage.common.pojo.ScsVo;
import com.z6school.manage.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
@RequestMapping("/score/")
public class ScoreController {

    @Autowired
    private ScoreService scoreService;

    @RequestMapping("findObjectByClassId")
    @ResponseBody
    public JsonResult findObjectByClassId(Integer classId){
        List<ScoreVo> objects = scoreService.findObjects(classId);

        return new JsonResult(objects);
    }
    @RequestMapping("doGetCurrNames")
    @ResponseBody
    public JsonResult doGetCurrNames(Integer classId){
        System.out.println("controller"+classId);
        List<String> currNames = scoreService.getCurrNames(classId);
        System.err.println(currNames);
        return new JsonResult(currNames);
    }
    @RequestMapping("doSaveScores")
    @ResponseBody
    public JsonResult doSaveScores(){
        //scoreService.saveScores();
        return new JsonResult("save ok");
    }

    @RequestMapping("doFindOne")
    @ResponseBody
    public  JsonResult doFindOne(Integer studentId){
        ScoreVo one = scoreService.findOne(studentId);
        return new JsonResult(one);
    }
    @RequestMapping("findNameByCurrId")
    @ResponseBody
    public  JsonResult findNameByCurrId(Integer currId){
        String currName = scoreService.findNameByCurrId(currId);
        return new JsonResult(currName);
    }

    @RequestMapping("doUpdateScores")
    @ResponseBody
    public JsonResult doUpdateScores(ScsVo scsVo){
        System.out.println("update"+scsVo.getStudentId());
        System.err.println("update"+scsVo.getCurrIds());
        System.err.println("update"+scsVo.getScores());
        scoreService.updateScores(scsVo);
        return new JsonResult("修改成功");
    }
    @RequestMapping("getCurrIds")
    @ResponseBody
    private JsonResult getCurrIds(Integer studentId){
        List<Integer> currIds = scoreService.getCurrIds(studentId);
        return  new JsonResult(currIds);
    }

    @RequestMapping("getCurrName")
    @ResponseBody
    private JsonResult getCurrName(Integer currId){
        String currName = scoreService.getCurrName(currId);
        return new JsonResult(currName);
    }
    @RequestMapping("getClassIds")
    @ResponseBody
    private JsonResult getClassIds(Integer studentId){
        Integer classId = scoreService.getClassId(studentId);

        return  new JsonResult(classId);
    }
}
